/**
 *  File: CipherOldApi.java
 *  Date         Author      Changes
 *  2016-10-7    wangtq       Create
 *
 */
package com.kunpu.framework.security.old;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

/**
 * 老蚂米平台加解密对外API
 * @author wangtq
 * @date 2016-10-7 下午18:29
 * @version 0.1
 *
 */
public class CipherOldApi {

	/**
	 * 加密
	 * @param salt        加密key
	 * @param ciphertext  加密原文字符串
	 * @return encrptStr 加密密文
	 */
	public static String  encrypt(String salt,String ciphertext){
		Assert.isTrue(!StringUtils.isEmpty(salt),"加密key不能为空");
		Assert.isTrue(!StringUtils.isEmpty(ciphertext),"加密串不能为空");
		byte[] keyBystes = Encodes.decodeHex(salt);
	   	byte[] bytes2 = Cryptos.aesEncrypt(ciphertext.getBytes(), keyBystes);
	   	String encrptStr = Encodes.encodeHex(bytes2);
		return encrptStr;
	}	
	
	/**
	 * 解密
	 * @param salt        解密key
	 * @param ciphertext  解密密文
	 * @return decryptStr 解密原文
	 */
	public static String  decrypt(String salt,String ciphertext){
		Assert.isTrue(!StringUtils.isEmpty(salt),"解密key不能为空");
		Assert.isTrue(!StringUtils.isEmpty(ciphertext),"解密密文串不能为空");
		byte[] keyBystes = Encodes.decodeHex(salt);   
	   	byte[] dinput = Encodes.decodeHex(ciphertext);
	   	String decryptStr = Cryptos.aesDecrypt(dinput, keyBystes);
		return decryptStr;
	}
	
	
}
